from flask import Blueprint,jsonify,request,abort
from flask_restful import Api,Resource
from app.models import *
school0 = Api()

class School1(Resource):
    def get(self):
        am = School.query.all()
        return jsonify({"am": list(map(con3, am))})
    def post(self, uid):
        ak = School(
            request.json["enterprise_name"],
            request.json["contact_person"],
            request.json["telephone_number"],
            request.json["graduation_people"],
            request.json["return_money"],
            request.json["receipt_day"]
        )
        db.session.add(ak)
        db.session.commit()
        return jsonify({"ak": con3(ak)})
school0.add_resource(School1, "/School1/")


class School2(Resource):
    def get(self, uid):
        azz = School.query.filter_by(id=uid).first()
        if azz is None:
            abort(404)
        return jsonify({"aj": con3(azz)})

    def put(self, uid):
        al = School.query.get(uid)
        al.enterprise_name = request.json.get("enterprise_name")
        al.contact_person = request.json.get("contact_person")
        al.telephone_number = request.json.get("telephone_number")
        al.graduation_people = request.json.get("graduation_people")
        al.return_money = request.json.get("return_money")
        al.receipt_day = request.json.get("receipt_day")
        db.session.add(al)
        return jsonify({"al": con3(al)})


school0.add_resource(School2, "/School2/<int:uid>/")